package com.price.sample.http.person

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider
import com.price.sample.http.beans.WanBaseResponse
import com.price.sample.http.beans.BannerWithDefNPEField
import com.price.sample.http.beans.ListResponseBean
import com.price.sample.http.myinterface.WannaAndroidApi
import com.price.sample.http.service.WanAndroidApiService


/**
 * ViewModel 没啥好说的
 * 把业务搬这？
 */
class HomeViewModel(private val repo: WannaAndroidApi) : ViewModel() {

    companion object {
        val Factory: ViewModelProvider.Factory = object : ViewModelProvider.Factory {
            override fun <T : ViewModel> create(modelClass: Class<T>): T {
                return HomeViewModel(WanAndroidApiService.getService()) as T
            }
        }
    }

    suspend fun getBanner(): WanBaseResponse<List<BannerWithDefNPEField>> {
        return repo.getBanner()
    }
    suspend fun getList(): WanBaseResponse<ListResponseBean> {
        return repo.getList()
    }

    suspend fun getTest(): WanBaseResponse<Any> {
        return repo.getTest()
    }
    //同步不能suspend
     fun getTest1(): WanBaseResponse<Any> {
        val call=repo.getTest1().execute()
        return call.body()!!

//        return repo.getTest()
    }

}